/****************************************************************************
**
** Copyright (C) 2003-2005 Trolltech AS. All rights reserved.
**
** This file is part of a Qt Solutions component.
**
** Licensees holding valid Qt Solutions licenses may use this file in
** accordance with the Qt Solutions License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/products/solutions/index.html 
** or email sales@trolltech.com for information about Qt Solutions
** License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef QTTELNET_H
#define QTTELNET_H

#include <QObject>
#include <QString>
#include <QSize>
#include <QRegExp>
#include <QTcpSocket>

class QtTelnetPrivate;

class QtTelnet : public QObject
{
    Q_OBJECT
    friend class QtTelnetPrivate;
public:
    QtTelnet(QObject *parent = 0);
    ~QtTelnet();

    enum Control { GoAhead, InterruptProcess, AreYouThere, AbortOutput,
                   EraseCharacter, EraseLine, Break, EndOfFile, Suspend,
                   Abort };

    void connectToHost(const QString &host, quint16 port = 23);
    void disconnectFromHost();

    void login(const QString &user, const QString &pass);
    void login();

    void setWindowSize(const QSize &size);
    void setWindowSize(int width, int height); // In number of characters
    QSize windowSize() const;
    bool isValidWindowSize() const;

    void setSocket(QTcpSocket *socket);
    QTcpSocket * socket() const;

    void setLoginPattern(const QRegExp &pattern);
    void setLoginString(const QString &pattern) { setLoginPattern(QRegExp(QRegExp::escape(pattern))); }
    
    void setPromptPattern(const QRegExp &pattern);
    void setPromptString(const QString &pattern)  { setPromptPattern(QRegExp(QRegExp::escape(pattern))); }
    
    void setPasswordPattern(const QRegExp &pattern);
    void setPasswordString(const QString &pattern) { setPasswordPattern(QRegExp(QRegExp::escape(pattern))); }
    
public slots:
    void close();
    void logout();
    void sendControl(Control ctrl);
    void sendData(const QString &data);    
    void sendSync();
    //saa
    void sendEscapeSequence();

signals:
    void loginRequired();
    void loginFailed();
    void loggedIn();
    void loggedOut(); 
    void connected();

    void connectionError(QAbstractSocket::SocketError error);
    void message(const QString &data);

private:
    QtTelnetPrivate *d;
};
#endif
